﻿using System;

namespace Vk.Authorization
{
    public struct VkSession
    {
        public VkSession(int appId)
        {
            AppId = appId;
            Expires = DateTime.Now;
            AccessToken = string.Empty;
            UserId = -1;
            Permissions = null;
        }

        public string AccessToken { get; internal set; }
        public int AppId { get; internal set; }
        public DateTime Expires { get; internal set; }
        public int UserId { get; internal set; }
        public ApiAccessPermissions Permissions { get; }

        public bool IsValid()
        {
            return !string.IsNullOrWhiteSpace(AccessToken) && Expires.Ticks > DateTime.Now.Ticks;
        }

        public bool Equals(VkSession other)
        {
            return string.Equals(AccessToken, other.AccessToken);
        }

        public override string ToString()
        {
            return string.Format("App: {0} AccessToken: {1} Expires: {2}", AppId, AccessToken, Expires.ToString("g"));
        }
    }
}